/**
 * 依赖jquery和layer
 */

/**
 * a标签跳转前验证
 * @param  {[type]} m [description]
 * @param  {[type]} c [description]
 * @param  {[type]} a [description]
 * @return {[type]}   [description]
 */
function checkBeforeJump(m, c, a) {
  $.ajax({
      url: '?m=admin&c=Index&a=checkBeforeJump',
      type: 'post',
      dataType: 'json',
      data: {module: m, controller: c, action: a},              
      success: function(data){
        // console.log(data);
          if (data.code == 200) {
            window.location = '?m=' + m + '&c=' + c + '&a=' + a;
          }else if (data.code == 401) {
            layer.msg(data.msg);
          }else if (data.code == 403) {
            layer.msg(data.msg);
          }else{
            layer.msg('未知错误！');
          }
      }
  })
  .fail(function(jqXHR,textStatus,errorThrown){
     console.log(jqXHR);
     console.log(textStatus);
     console.log(errorThrown);
  });
}

/**
 * 退出登录
 * @return {[type]} [description]
 */
function logout() {
  $.ajax({
      url: '?m=admin&c=Login&a=logout',
      type: 'post',
      dataType: 'json',
      data: {},             
      success: function(data){
          if (data.code == 200) {
              layer.msg(data.msg, function () {
                  window.location = '?m=admin&c=Login&a=index';
              });
          }else{
              layer.msg(data.msg);
          }  
      }
  });
}